package com.turing.post.antimoney.impl;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import com.turing.post.antimoney.util.SuspiciousReport;
import com.turing.post.antimoney.util.SuspiciousReportDao;
import com.turing.post.antimoney.util.SuspiciousTrans;
import com.turing.post.antimoney.util.SuspiciousTransBusiness;
import com.turing.post.antimoney.util.SuspiciousTransDao;
import com.turing.post.common.util.SysOperLog;
import com.turing.post.common.util.SysOperLogDao;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSWebInput;

/**
 * @author 李治
 * 
 */
@Remote
@Local
@Stateless(mappedName = "antimoney.impl.SuspiciousTransBusinessImpl")
public class SuspiciousTransBusinessImpl implements SuspiciousTransBusiness {
	@EJB(mappedName = "antimoney.impl.SuspiciousTransDaoImpl")
	private SuspiciousTransDao suspiciousTransDaoImpl;
	@EJB(mappedName = "antimoney.impl.SuspiciousReportDaoImpl")
	private SuspiciousReportDao suspiciousReportDaoImpl;

	@EJB(mappedName = "common.impl.SysOperLogDaoImpl")
	private SysOperLogDao sysOperLogDaoImpl;

	@Override
	public void deleteSuspiciousTrans(PCPSWebInput webInput,
			SuspiciousTrans suspiciousTrans) throws PCPSApplicationException {
		if (null == suspiciousTrans || null == suspiciousTrans.getAlarmInfoId()
				|| null == suspiciousTrans.getSeqNo()) {
			throw new PCPSApplicationException(
					PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION, "",
					"参数为空");
		}
		SuspiciousTrans _SuspiciousTrans = suspiciousTransDaoImpl
				.getSuspiciousTransById(suspiciousTrans);
		if (null == _SuspiciousTrans) {
			throw new PCPSApplicationException(
					PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION, "",
					"可疑交易明细不存在");
		}
		// 日志记录
		sysOperLogDaoImpl.insertSysOperLogInfo(webInput,
				SysOperLog.operType_Delete, "删除可疑交易", "ReportId:"
						+ _SuspiciousTrans.getReportId());
		suspiciousTransDaoImpl.deleteSuspiciousTrans(_SuspiciousTrans);
	}

	@Override
	public void updateSuspiciousTrans(PCPSWebInput webInput, SuspiciousTrans s)
			throws PCPSApplicationException {
		if (null == s || null == s.getAlarmInfoId() || null == s.getSeqNo()) {
			throw new PCPSApplicationException(
					PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION, "",
					"参数为空");
		}
		if (null == webInput || null == webInput.getOperId()) {
			throw new PCPSApplicationException(
					PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION, "",
					"业务处理webservice输入值为空");
		}
		SuspiciousTrans _SuspiciousTrans = suspiciousTransDaoImpl
				.getSuspiciousTransById(s);
		if (null == _SuspiciousTrans) {
			throw new PCPSApplicationException(
					PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION, "",
					"可疑交易明细不存在");
		}
		if (null != _SuspiciousTrans.getReportId()) {
			SuspiciousReport report = suspiciousReportDaoImpl
					.getSuspiciousReportById(_SuspiciousTrans.getReportId());
			if (null != report && "1".equals(report.getReportStatus())) {
				throw new PCPSApplicationException(
						PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION,
						"", "可疑交易明细正在上报中，不允许修改");
			}
			if (null != report && "2".equals(report.getReportStatus())) {
				throw new PCPSApplicationException(
						PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION,
						"", "可疑交易明细已上报成功，不允许修改");
			}
		}
		_SuspiciousTrans.setReportId(s.getReportId());
		_SuspiciousTrans.setBPTC(s.getBPTC());
		_SuspiciousTrans.setCABM(s.getCABM());
		_SuspiciousTrans.setCBAC(s.getCBAC());
		_SuspiciousTrans.setCBAT(s.getCBAT());
		_SuspiciousTrans.setCCTL(s.getCCTL());
		_SuspiciousTrans.setCEML(s.getCEML());
		_SuspiciousTrans.setCITP(s.getCITP());
		_SuspiciousTrans.setCPBA(s.getCPBA());
		_SuspiciousTrans.setCPBN(s.getCPBN());
		_SuspiciousTrans.setCPIN(s.getCPIN());
		_SuspiciousTrans.setCRAT(s.getCRAT());
		_SuspiciousTrans.setCRID(s.getCRID());
		_SuspiciousTrans.setCRIT(s.getCRIT());
		_SuspiciousTrans.setCRNM(s.getCRNM());
		_SuspiciousTrans.setCRPP(s.getCRPP());
		_SuspiciousTrans.setCRTP(s.getCRTP());
		_SuspiciousTrans.setCTAC(s.getCTAC());
		_SuspiciousTrans.setCTAR(s.getCTAR());
		_SuspiciousTrans.setCTAT(s.getCTAT());
		_SuspiciousTrans.setCTID(s.getCTID());
		_SuspiciousTrans.setCTIP(s.getCTIP());
		_SuspiciousTrans.setCTNM(s.getCTNM());
		_SuspiciousTrans.setCTTP(s.getCTTP());
		_SuspiciousTrans.setCTVC(s.getCTVC());
		_SuspiciousTrans.setPMTC(s.getPMTC());
		_SuspiciousTrans.setSMID(s.getSMID());
		_SuspiciousTrans.setSTIF(s.getSTIF());
		_SuspiciousTrans.setTCAT(s.getTCAT());
		_SuspiciousTrans.setTCBA(s.getTCBA());
		_SuspiciousTrans.setTCBN(s.getTCBN());
		_SuspiciousTrans.setTCID(s.getTCID());
		_SuspiciousTrans.setTCIP(s.getTCIP());
		_SuspiciousTrans.setTCIT(s.getTCIT());
		_SuspiciousTrans.setTCNM(s.getTCNM());
		_SuspiciousTrans.setTCPA(s.getTCPA());
		_SuspiciousTrans.setTCPN(s.getTCPN());
		_SuspiciousTrans.setTCTA(s.getTCTA());
		_SuspiciousTrans.setTCTT(s.getTCTT());
		_SuspiciousTrans.setTICD(s.getTICD());
		_SuspiciousTrans.setTMNM(s.getTMNM());
		_SuspiciousTrans.setTPBN(s.getTPBN());
		_SuspiciousTrans.setTSDR(s.getTSDR());
		_SuspiciousTrans.setTSMI(s.getTSMI());
		_SuspiciousTrans.setTSTM(s.getTSTM());
		suspiciousTransDaoImpl.updateSuspiciousTrans(_SuspiciousTrans);
		// 日志记录
		sysOperLogDaoImpl.insertSysOperLogInfo(webInput,
				SysOperLog.operType_Edit, "修改可疑交易", "ReportId:"
						+ _SuspiciousTrans.getReportId());
	}
}
